﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Controls;
using System.IO;
using ESRI.ArcGIS.Geodatabase;

namespace Homework5
{
    public partial class Form3 : Form
    {

        
        IMap pMap;
        
        private IFeatureLayer layer2Symbolize;
        


        public Form3()
        {
            InitializeComponent();
        }
        public Form3(IMap map)
        {
            pMap = map;
            InitializeComponent();
            
        }
        //关闭窗口
        private void button3_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void Form3_Load(object sender, EventArgs e)
        {

            if (pMap.LayerCount != 0)
                layer2Symbolize = pMap.get_Layer(0) as IFeatureLayer;

            //为图层添加下拉框内容
            comboBox2.Items.Clear();
            for (int i = 0; i < pMap.LayerCount; i++)
            {
                comboBox2.Items.Add(pMap.get_Layer(i).Name);
                
            }
        }

        

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton2.Checked)
                textBox1.Enabled = true;
            else textBox1.Enabled = false;
        }
        //为图形下拉框添加内容
        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            string layer = comboBox2.SelectedItem.ToString();
            ILayer select_layer = null;
            for(int i = 0;i < pMap.LayerCount;i++)
            {
                if(pMap.get_Layer(i).Name == layer)
                {
                    select_layer = pMap.get_Layer(i);
                }
            }
            if(select_layer != null)
            {
                IFeatureLayer select_flayer = select_layer as FeatureLayer;
                IFeatureClass pFClass = select_flayer.FeatureClass;
                IFields pFields = pFClass.Fields;


                //储存属性字段名
                for (int i = 0; i < pFields.FieldCount; i++)
                {
                    comboBox3.Items.Add(pFields.get_Field(i).Name);

                }


            }
        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton1.Checked)
            {
                comboBox2.Enabled = true;
                comboBox3.Enabled = true;
            }
            else
            {
                comboBox2.Enabled = false;
                comboBox3.Enabled = false;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            
            if(radioButton1.Checked)
            {
                string field_name = comboBox3.Text;
                int layer_index = comboBox2.SelectedIndex;
                Form1.form1.唯一值符号化(field_name,layer_index);
            }
            else if (radioButton2.Checked)
            {
                string field_name = textBox1.Text;
                Form1.form1.唯一值符号化(field_name);
            }
        }

    }
}
